package com.envisioniot.test;

import com.envisioniot.test.service.Demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.stream.IntStream;

@EnableCaching
@RestController
@RequestMapping("/")
@SpringBootApplication
public class App {


    public static void main(String[] args) throws Exception {
        SpringApplication application = new SpringApplication(App.class);
        application.setApplicationContextClass(AnnotationConfigWebApplicationContext.class);
        SpringApplication.run(App.class, args);
    }

    @Autowired
    private Demo demo;

    @RequestMapping
    public Map Test() {
        int i = new Random().nextInt(15);
        int ii = new Random().nextInt(10);
        String collect = IntStream.rangeClosed(1, i).collect(ArrayList::new, (x, y) -> x.add(y * ii), (xx, yy) -> xx.addAll(yy)).toString();
        System.out.println(collect + Instant.now());
        return new HashMap() {{
            put("code", collect);
            put("time", Instant.now());
            put("cache", demo.getTree());
        }};
    }
}
